package com.weasing.res.service.base.impl;

import java.io.Serializable;
import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;

import com.weasing.res.dao.base.IBaseDao;
import com.weasing.res.service.base.IBaseService;
import com.weasing.res.utils.PageBean;

public class BaseServiceImpl<T> implements IBaseService<T> {
	private Class<T> entityClass;
	@Autowired
	private IBaseDao<T> dao;

	// 用构造器里面或者调用之类的 模板对象的class
	public BaseServiceImpl() {
			ParameterizedType superclass = (ParameterizedType) this.getClass().getGenericSuperclass();
			// 用构造器得到调用这个类的类名class并且复制给 成员变量entityClass
			Type[] actualTypeArguments = superclass.getActualTypeArguments();
			entityClass = (Class<T>) actualTypeArguments[0];
		}

	@Override
	public void save(T entity) {
		dao.save(entity);

	}

	@Override
	public void saveOrUpdate(T entity) {
		dao.saveOrUpdate(entity);

	}

	@Override
	public void delete(T entity) {
		dao.delete(entity);
	}

	@Override
	public void update(T entity) {
		dao.update(entity);
	}

	@Override
	public T findById(Serializable id) {
		T findById = dao.findById(id);
		return findById;
	}

	@Override
	public List<T> findAll() {
		List<T> findAll = dao.findAll();
		return findAll;
	}


	@Override
	public void pageQuery(PageBean pageBean) {
		dao.pageQuery(pageBean);

	}

	@Override
	public Integer findCount() {
		Integer findCount = dao.findCount();
		return findCount;
	}

	@Override
	public List<T> findAllByParentId(Integer parentId) {
		return dao.findAllByParentId(parentId);
	}

	@Override
	public void pageQuery(PageBean pageBean, Map<String, Object> map) {
		dao.pageQuery(pageBean, map);
	}

	@Override
	public Integer findCountByField(Map<String, Object> map) {
		return dao.findCountByField(map);
	}

}
